<template>
  <div>
      <van-address-list 
        :list="list"
        @add="hanldeAdd"
        @edit="hanldeEdit"
        :switchable="false"
      />
  </div>
</template>

<script>
import {getList} from "@/api"
import {loading,clearToast} from "@/utils/loading"
export default {
    data(){
        return {
            list:[]
        }
    },
    methods:{
        formatList(list){
            return list.map(item =>({...item,tel:item.phone,address:item.addressinfo}))
        },
        hanldeAdd(){
            this.$router.push('/address/add')
        },
        hanldeEdit({id}){
            this.$router.push({
                path:"/address/edit",
                query:{
                    id
                }
            })
        }
    },
    mounted(){
        loading();
        getList().then(res => {
            this.list = this.formatList(res.data);
            clearToast();
        })
    }
}
</script>

<style>

</style>